﻿# -*- coding:utf-8 -*-
from django.db import models
from django.contrib.auth.models import User
from django.contrib import admin


LOCATION_CHOICES = (
    ('str', 'Склад'),
    ('rpr', 'Ремонт'),
    ('exp', 'Экспозиция'),
    ('exh', 'Выставка'),
)

VERBOSE_LOCATION_CHOICES = (
    ('Склад', 'Склад'),
    ('Ремонт', 'Ремонт'),
    ('Экспозиция', 'Экспозиция'),
    ('Выставка', 'Выставка'),
)

class Exhibition(models.Model):
    name = models.CharField(max_length=128, blank=True, verbose_name="Название") 
    room = models.CharField(max_length=8, verbose_name="Зал/Помещение")
    location = models.CharField(max_length=64, blank=True, verbose_name="Расположение")
    comment = models.CharField(max_length=128, blank=True, verbose_name="Примечание")    
    presentation_name = models.CharField(max_length=8, blank=True, verbose_name="Презентация")
    presentation_file = models.FileField(blank=True, verbose_name="Файл презентации", upload_to="D:/srv/www/django/ktit/media/ppt")
    date_open = models.DateTimeField(blank=True, null=True, verbose_name="Открытие")
    date_close = models.DateTimeField(blank=True, null=True, verbose_name="Закрытие")

    def __unicode__(self):
        return u"%s зал %s" % (self.name, self.room) 



class Equipment(models.Model):
    name = models.CharField(max_length=64, verbose_name="Наименование")
    category = models.CharField(max_length=64, verbose_name="Категория")
    
    def __unicode__(self):
        return self.name 



class Device(models.Model):
    equipment = models.ForeignKey(Equipment, verbose_name="Оборудование")
    serial_number = models.CharField(max_length=64, verbose_name="Серийный номер")
    inv_number = models.CharField(max_length=64, blank=True, verbose_name="Инвентарный номер")
    location = models.CharField(max_length=3, choices=LOCATION_CHOICES, verbose_name="ID Расположение")
    verbose_location = models.CharField(max_length=16, choices=VERBOSE_LOCATION_CHOICES, verbose_name="ID Расположение")
    exhibition = models.ForeignKey(Exhibition, blank=True, null=True, verbose_name="Выставка")
    cpu = models.CharField(max_length=32, blank=True, verbose_name="Процессор")
    memory = models.CharField(max_length=32, blank=True, verbose_name="Память")
    hdd = models.CharField(max_length=32, blank=True, verbose_name="Жесткий диск")
    tech_info = models.TextField(blank=True, verbose_name="Техническая информация")
    
    def __unicode__(self):
        return u"%s - %s / %s" % (self.equipment, self.serial_number, self.inv_number)

       


class History(models.Model):
    device = models.ForeignKey(Device, verbose_name="Оборудование")
    action = models.TextField(editable=False, blank=True, verbose_name="Событие")
    comment = models.CharField(max_length=128, blank=True, verbose_name="Примечание")
    date = models.DateTimeField(auto_now_add=True, verbose_name="Дата")
    user = models.ForeignKey(User, verbose_name="Пользователь")

    def __unicode__(self):
        return "%s - %s" % (self.date, self.action) 
        
        
